import { takeEvery } from 'redux-saga';
import { put, call } from 'redux-saga/effects'
import { LOAD, LOAD_SUCCESS, LOAD_FAIL } from './constants';
import {ax_get} from '../../utils/ax_agent'

export default function* postSaga() {
  yield [
    getGamePostData()
  ]
}

function* fetchPost(action) {
   try {

      const result = yield call( ax_get,  '/api/gamePost', {params: {page: action.page_number}} )

      yield put({type: LOAD_SUCCESS, result: result.data})
   
   } catch (e) {

      yield put({type: LOAD_FAIL, message: e.message})

   }
}

function* getGamePostData() {
  yield* takeEvery( LOAD, fetchPost)
}